package com.movecar.ui;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.movecar.R;
import com.movecar.model.GetGroupBean.Comments;

/**
 * 全部讨论
 * 
 * @author Zhao.JQ
 * 
 */
public class LookDiscussActivity extends Activity implements OnClickListener {
	private ArrayList<Comments> commentsData;
	private ListView mListView;

	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);
		setContentView(R.layout.look_discuss);
		initView();
	}

	@SuppressWarnings("unchecked")
	private void initView() {
		mListView = (ListView) findViewById(R.id.mListView);
		Button back = (Button) findViewById(R.id.btn_left);
		back.setVisibility(View.VISIBLE);
		back.setOnClickListener(this);

		TextView title = (TextView) findViewById(R.id.title);
		title.setText("全部讨论");
		if (this.getIntent() != null) {
			commentsData = (ArrayList<Comments>) getIntent()
					.getSerializableExtra("comments");
			DataAdapter dataAdapter = new DataAdapter(LookDiscussActivity.this,
					commentsData);
			mListView.setAdapter(dataAdapter);
		}

	}

	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_left:
			finish();
			break;

		default:
			break;
		}

	}

	class DataAdapter extends BaseAdapter {
		private LayoutInflater inflater;
		private ViewHolder viewHolder = null;
		private ArrayList<Comments> commentsData;

		DataAdapter(Activity activity, ArrayList<Comments> commentsData) {
			this.commentsData = commentsData;
			inflater = LayoutInflater.from(activity);
		}

		@Override
		public int getCount() {
			return commentsData.size();
		}

		@Override
		public Object getItem(int arg0) {
			return commentsData.get(arg0);
		}

		@Override
		public long getItemId(int arg0) {
			return arg0;
		}

		@Override
		public View getView(final int position, View view, ViewGroup arg2) {
			if (view == null) {
				viewHolder = new ViewHolder();
				view = inflater.inflate(R.layout.look_discuss_item, null);

				viewHolder.userNickName = (TextView) view
						.findViewById(R.id.userName);
				viewHolder.content = (TextView) view.findViewById(R.id.content);
				viewHolder.createDate = (TextView) view
						.findViewById(R.id.createDate);

				view.setTag(viewHolder);
			} else {
				viewHolder = (ViewHolder) view.getTag();
			}
			String nickName = commentsData.get(position).getUserNickName().toString();

			viewHolder.userNickName.setText(nickName);
			viewHolder.content.setText(commentsData.get(position).getContent());
			viewHolder.createDate.setText(commentsData.get(position)
					.getCreateDate());

			// }
			return view;
		}

		class ViewHolder {
			TextView userNickName, content, createDate;
			LinearLayout myLayout;
			ImageView group_img, isjoin;
			Button group_join, group_discuss;
		}
	}
}
